<?php
include_once dirname(__FILE__) . "/../config/functions.php";
include_once dirname(__FILE__) . "/header.php";
?>


<div id="page-wrapper">

    <div class="row">
        <div class="col-lg-12">
            <?php
            //get member data
            if (!isset($_GET['id']) || !$_GET['id']):
                ?>
                <div class="alert alert-danger">
                    Member Not Found.
                </div>
                <?php
            else:
                $edit = FALSE;
                if (isset($_POST) && $_POST) {
                    $status = 0;
                    if (isset($_POST['user_activation_status']) && $_POST['user_activation_status'] == 1)
                        $status = 1;

                    if (isset($_POST['user_password']) && $_POST['user_password']) {
                        $password = $_POST['user_password'];
                        mysql_query("update `user` set `password` = '$password',`status` = '$status',`url` = '" . $_POST['user_url'] . "',`textAd` = '" . $_POST['user_ad'] . "',`name` = '" . $_POST['user_name'] . "',`email` = '" . $_POST['user_email'] . "' where `id` = '" . $_GET['id'] . "' ");
                    } else {
                        mysql_query("update `user` set `status` = '$status',`url` = '" . $_POST['user_url'] . "',`textAd` = '" . $_POST['user_ad'] . "',`name` = '" . $_POST['user_name'] . "',`email` = '" . $_POST['user_email'] . "' where `id` = '" . $_GET['id'] . "' ");
                    }
                    $edit = TRUE;
                }

                $member = mysql_query("select * from user where id = " . $_GET['id']);
                $row = mysql_fetch_assoc($member);
                if ($row):
                    ?>
                    <h1>Edit <small><?php echo $row['name']; ?></small></h1>
                    <div class="editMemeber">
                        <?php if ($edit): ?>
                            <div class="alert alert-success alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                Member updated successfully.
                            </div>
                        <?php endif; ?>
                        <form class="form-horizontal" role="form" method="post">
                            <div class="form-group">
                                <label for="user_name" class="col-sm-2 control-label">Name</label>
                                <div class="col-sm-10">
                                    <input type="text" value="<?php echo $row['name']; ?>" class="form-control" name="user_name" id="user_name">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="user_email" class="col-sm-2 control-label">Email</label>
                                <div class="col-sm-10">
                                    <input type="text" value="<?php echo $row['email']; ?>" class="form-control" name="user_email" id="user_email">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="user_name" class="col-sm-2 control-label">Username</label>
                                <div class="col-sm-10">
                                    <p><?php echo $row['username']; ?></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="user_password" class="col-sm-2 control-label">Password</label>
                                <div class="col-sm-10">
                                    <input type="text" value="<?php echo $row['password']; ?>" class="form-control" name="user_password" id="user_password">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="user_ad" class="col-sm-2 control-label">Ad Title</label>
                                <div class="col-sm-10">
                                    <input type="text" value="<?php echo $row['textAd']; ?>" class="form-control" name="user_ad" id="user_ad">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="user_url" class="col-sm-2 control-label">Url</label>
                                <div class="col-sm-10">
                                    <input type="text" value="<?php echo $row['url']; ?>" class="form-control" name="user_url" id="user_url">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="user_activation_status" class="col-sm-2 control-label">Activation Status</label>
                                <div class="col-sm-10">
                                    <input type="checkbox" value="1" <?php if ($row['status'] == 1): ?>checked=""<?php endif; ?> class="form-control" name="user_activation_status" id="user_activation_status">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button type="submit" class="btn btn-primary">Update</button>
                                </div>
                            </div>
                        </form>
                    </div>
                <?php else: ?>
                    <div class="alert alert-danger">
                        Member Not Found.
                    </div>
                <?php endif; ?>
            <?php endif; ?>

        </div>
    </div><!-- /.row -->

</div><!-- /#page-wrapper -->

<?php include_once dirname(__FILE__) . "/footer.php"; ?>